package com.harveyguo.nihonngo.controller;

import com.harveyguo.nihonngo.model.dto.CoachDto;
import com.harveyguo.nihonngo.service.CoachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 教练Controller
 */
@RestController
@RequestMapping("/api/coaches")
public class CoachController {

    @Autowired
    private CoachService coachService;

    /**
     * 创建教练
     */
    @PostMapping
    public ResponseEntity<CoachDto> createCoach(@RequestBody CoachDto coachDto) {
        return ResponseEntity.ok(coachService.createCoach(coachDto));
    }

    /**
     * 根据ID查找教练
     */
    @GetMapping("/{id}")
    public ResponseEntity<CoachDto> getCoach(@PathVariable String id) {
        return ResponseEntity.ok(coachService.findById(id));
    }

    /**
     * 查找所有教练
     */
    @GetMapping
    public ResponseEntity<List<CoachDto>> getAllCoaches() {
        return ResponseEntity.ok(coachService.findAll());
    }

    /**
     * 根据拳馆ID查找教练
     */
    @GetMapping("/gym/{gymId}")
    public ResponseEntity<List<CoachDto>> getCoachesByGym(@PathVariable String gymId) {
        return ResponseEntity.ok(coachService.findByGymId(gymId));
    }

    /**
     * 根据认证状态查找教练
     */
    @GetMapping("/verified/{verified}")
    public ResponseEntity<List<CoachDto>> getCoachesByVerified(@PathVariable Boolean verified) {
        return ResponseEntity.ok(coachService.findByVerified(verified));
    }

    /**
     * 根据专长查找教练
     */
    @GetMapping("/speciality/{speciality}")
    public ResponseEntity<List<CoachDto>> getCoachesBySpeciality(@PathVariable String speciality) {
        return ResponseEntity.ok(coachService.findBySpeciality(speciality));
    }

    /**
     * 查找附近的教练
     */
    @GetMapping("/nearby")
    public ResponseEntity<List<CoachDto>> getNearbyCoaches(
            @RequestParam Double latitude,
            @RequestParam Double longitude,
            @RequestParam(defaultValue = "10.0") Double radius) {
        return ResponseEntity.ok(coachService.findNearbyCoaches(latitude, longitude, radius));
    }

    /**
     * 更新教练信息
     */
    @PutMapping("/{id}")
    public ResponseEntity<CoachDto> updateCoach(@PathVariable String id, @RequestBody CoachDto coachDto) {
        return ResponseEntity.ok(coachService.updateCoach(id, coachDto));
    }

    /**
     * 删除教练
     */
    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteCoach(@PathVariable String id) {
        coachService.deleteCoach(id);
        return ResponseEntity.ok().build();
    }

    /**
     * 认证教练
     */
    @PostMapping("/{id}/verify")
    public ResponseEntity<CoachDto> verifyCoach(@PathVariable String id) {
        return ResponseEntity.ok(coachService.verifyCoach(id));
    }
}